﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Howork.Account
{
    public partial class Register : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void BtnReg_Click(object sender, EventArgs e)
        {
            String idreg = userID.Text;
            String namereg = userName.Text;
            String passreg = pass.Text;
            String passconreg = passConfirm.Text;
            if(idreg.Length>0&&namereg.Length>0&&passreg.Length>0&&passconreg.Length>0&&passconreg==passreg)
            {
                //注册
                try
                {
                    String strConnection = "server=.\\SQLEXPRESS;database=howork_c;uid=Yuleo;pwd=yuleoyubin;";
                    SqlConnection Connection = new SqlConnection(strConnection);
                    String strSQL = "insert into employee values('" + idreg + "','" + namereg + "','" + passreg + "',null,null)";
                    SqlCommand command = new SqlCommand(strSQL, Connection);
                    Connection.Open();
                    if(command.ExecuteNonQuery() ==1)
                    {
                        Session["login"] = "login";  //是否登录 
                        Session["id"] = idreg;
                        Session["name"] = namereg;
                        Session["department_id"] = "";
                        Session["station_id"] = "";
                        RegMsg.Text = "注册成功，请等待管理员给您设置部门与岗位";
                        //Server.Transfer("/Default.aspx");
                    }
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    RegMsg.Text = "注册失败，用户名已存在";
                }
            }
            else
            {
                RegMsg.Text = "注册失败，请检查用户名和密码";
            }
        }

        

    }
}
